home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / LDimmableView / LDimmableView.cp next >
Encoding:
Text File  |  1994-12-29  |  3.8 KB  |  148 lines  |  [TEXT/CWIE]

  1. /*****************************************************************************
  2.     
  3.     LDimmableView.cp
  4.     Written by Rick Eames
  5.     ©1994 Natural Intelligence, Inc. && Rick Eames
  6.     
  7.     This class exists for one purpose only: to gray out a view that has 
  8.     been disabled.  This includes graying out all of the subviews within
  9.     that view.  To accomplish this, LDimmableView orders all of the sub-
  10.     views and attachments to draw themselves, checks to see if the view
  11.     is in a disabled state and grays out the view if it is. 
  12.     
  13.     The code also does the right thing if running under color.
  14.  
  15.     You have permission to use this class in any application you develop
  16.     as long as you credit both Rick Eames and Natural Intelligence, Inc. in
  17.     your credits.
  18.     
  19. *****************************************************************************/
  20.  
  21. #include "LDimmableView.h"
  22. #include <LView.h>
  23. #include <LList.h>
  24. #include <LListIterator.h>
  25. #include <LStream.h>
  26. #include <PP_Messages.h>
  27. #include <UDrawingState.h>
  28. #include "U3DAttachments.h"
  29. #include <UDrawingUtils.h>
  30.  
  31. /*****************************************************************************
  32.  LDimmableView
  33.     
  34.     Constructor from a stream.  Does nothing but call the LView constructor.
  35. *****************************************************************************/
  36.  
  37. LDimmableView::LDimmableView(LStream *inStream)
  38.     : LView(inStream)
  39. {
  40.  
  41. }
  42.  
  43. /*****************************************************************************
  44.  CreateDimmableViewStream
  45.  
  46.      Returns a new LDimmableView.
  47. *****************************************************************************/
  48.  
  49. LDimmableView *
  50. LDimmableView::CreateDimmableViewStream(LStream *inStream)
  51. {
  52.     return (new LDimmableView(inStream));
  53. }
  54.  
  55. /*****************************************************************************
  56.  DimInColor
  57.  
  58.      Using opCodes and PenModes, gray out a view.
  59. *****************************************************************************/
  60.  
  61. void LDimmableView::DimInColor(Rect *inDrawRect, unsigned short tint, Boolean makeLighter)
  62. {
  63.     StColorState        savedColorInfo;
  64.     StColorPenState        savedPenState;
  65.     RGBColor            newRGBColor, newOpColor;
  66.     short                arithPenMode;
  67.     
  68.     newOpColor.red = newOpColor.blue = newOpColor.green = tint;
  69.     
  70.     arithPenMode = blend;
  71.     
  72.     if (makeLighter) 
  73.         newRGBColor.red = newRGBColor.blue = newRGBColor.green = 0xFFFF;
  74.     else 
  75.         newRGBColor.red = newRGBColor.blue = newRGBColor.green = 0x0000;
  76.     
  77.     OpColor(&newOpColor);
  78.     RGBForeColor(&newRGBColor);
  79.     PenMode(arithPenMode);
  80.     PenPat(&qd.black);
  81.     PaintRect(inDrawRect);
  82. }
  83.  
  84. /*****************************************************************************
  85.  Draw
  86.  
  87.      Simple draw method.  If running under color it calls the DimInColor
  88.      method.  Otherwise it dims in a standard black and white method.
  89. *****************************************************************************/
  90.  
  91. void LDimmableView::Draw(RgnHandle inSuperDrawRgnH)
  92. {
  93.     if (IsVisible() && FocusDraw()) 
  94.     {
  95.         RectRgn(mUpdateRgnH, &mRevealedRect);
  96.         if (inSuperDrawRgnH != nil) 
  97.         {
  98.             SectRgn(inSuperDrawRgnH, mUpdateRgnH, mUpdateRgnH);
  99.         }
  100.         
  101.         if (!EmptyRgn(mUpdateRgnH)) 
  102.         {
  103.                                     // Some portion needs to be drawn
  104.             Rect    frame;
  105.             CalcLocalFrameRect(frame);
  106.             if (ExecuteAttachments(msg_DrawOrPrint, &frame)) 
  107.             {
  108.                 DrawSelf();
  109.             }
  110.             LListIterator iterator(mSubPanes, iterate_FromStart);
  111.             LPane    *theSub;
  112.             while (iterator.Next(&theSub)) 
  113.             {
  114.                 theSub->Draw(mUpdateRgnH);
  115.             }
  116.             
  117.             FocusDraw();
  118.             
  119.             if (mEnabled != triState_On)
  120.             {
  121.                 StDeviceLoop    theLoop(frame);
  122.                 Int16            depth;
  123.                 Rect            frame;
  124.                 
  125.                 CalcLocalFrameRect(frame);
  126.                 
  127.                 while (theLoop.NextDepth(depth))
  128.                 {
  129.                     if (depth >= 4)
  130.                     {
  131.                         DimInColor(&frame, 0x7530, true);
  132.                     }
  133.                     else
  134.                     {
  135.                         StColorPenState        savedPenState;    
  136.                         
  137.                         PenMode( patBic );
  138.                         PenPat(&qd.gray);
  139.                         PaintRect(&frame);
  140.                     }
  141.                 }
  142.             }
  143.  
  144.         }
  145.         SetEmptyRgn(mUpdateRgnH);
  146.     }
  147.     
  148. }